package com.cskaoyan.market.controller.wx;


import com.cskaoyan.market.db.domain.MarketAddress;
import com.cskaoyan.market.service.WxAddressService;
import com.cskaoyan.market.util.ResponseUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("wx/address")
public class WxAddressController {
    @Autowired
    WxAddressService wxAddressService;
    //查询用户当前收货地址
    @GetMapping("list")
    public Object list() {
        List<MarketAddress> addressList=wxAddressService.list();
        Object ok= ResponseUtil.okList(addressList);
        return ok;
    }
    //查看当前点击地址
    @GetMapping("detail")
    public Object detail(Integer id) {
        MarketAddress marketAddress=wxAddressService.detile(id);
        Object ok=ResponseUtil.ok(marketAddress);
        return ok;
    }
    //创建地址
    @PostMapping("save")
    public Object save(@RequestBody MarketAddress marketAddress) {
        Object i =wxAddressService.save(marketAddress);
        return i;
    }

    //删除地址
    @PostMapping("delete")
    public Object delete(@RequestBody Map<String,String> map) {
        Integer id=Integer.parseInt(map.get("id"));
        Integer i=wxAddressService.delete(id);
        if(i>0) {
            Object ok = ResponseUtil.ok();
            return ok;
        }
        return ResponseUtil.fail();
    }
}
